import BattleObj from "../../logic/battle/BattleObj";
import SkillTrigger from "./SkillTrigger";
import EventTrigger from "./impl/SkillEventTrigger";
import TriggerType from "./TriggerType";

/**
 * 技能触发管理器
 */
export default class SkillTriggerMgr {
    //所有技能触发器{触发类型:触发器实例}
    triggers: Map<number, SkillTrigger> = new Map();
    owner: BattleObj;//拥有者
    constructor(owner: BattleObj) {
        this.owner = owner;
    }

    addTrigger(skillId: number, triggerParams: number[][]) {
        //根据技能id拿到配置
        triggerParams.forEach(params => {
            let trigger = this.createTrigger(skillId, params[0], params)
            if(trigger != null){
                this.triggers.set(skillId, trigger);
            }
        })
    }

    public createTrigger(skillId: number, triggertType: number, params: number[]) {
        let trigger:SkillTrigger = null;
        switch (triggertType) {
            case TriggerType.Event:
                trigger = new EventTrigger(this.owner, params[0], skillId, params);
                break;
            default:
                console.error("未定义触发器类型:"+triggertType);
                break;
        }
        if(trigger != null) {
            trigger.init();
            this.triggers.set(triggertType, trigger);
        }
        return trigger;
    }
}